package com.javasm.controller;


import com.javasm.common.http.AxiosResult;
import com.javasm.common.page.PageResult;
import com.javasm.controller.base.BaseController;
import com.javasm.domin.criteria.AftersaleEnterDepotCriteria;
import com.javasm.domin.entity.AftersaleEnterDepot;
import com.javasm.domin.vo.AftersaleEnterDepotVo;
import com.javasm.service.AftersaleEnterDepotService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author ljy
 * @since 2022-01-16
 */
@RestController
@RequestMapping("aftersale-enter-depot")
@RequiredArgsConstructor
public class AftersaleEnterDepotController extends BaseController {

    private final AftersaleEnterDepotService aftersaleEnterDepotService;


    /**
     * 查询所有
     *
     * @param aftersaleEnterDepotCriteria
     * @return
     */
    @GetMapping("list")
    public AxiosResult<PageResult<AftersaleEnterDepotVo>> list(AftersaleEnterDepotCriteria aftersaleEnterDepotCriteria) {
        PageResult<AftersaleEnterDepotVo> list = aftersaleEnterDepotService.selectByPageCriteria(aftersaleEnterDepotCriteria);
        return AxiosResult.success(list);
    }

    /**
     * 根据id删除单条数据
     *
     * @param id
     * @return
     */
    @DeleteMapping("deleteById/{id}")
    public AxiosResult<Void> deleteById(@PathVariable Long id) {
        return toAxios(aftersaleEnterDepotService.deleteById(id));
    }

    /**
     * 根据id查询
     *
     * @param id
     * @return
     */
    @GetMapping("{id}")
    public AxiosResult<AftersaleEnterDepot> findById(@PathVariable Long id) {
        AftersaleEnterDepot byId = aftersaleEnterDepotService.getById(id);
        return AxiosResult.success(byId);
    }

    /**
     * 新增
     *
     * @param aftersaleEnterDepot
     * @return
     */
    @PostMapping("insert")
    public AxiosResult<Void> insert(@RequestBody AftersaleEnterDepot aftersaleEnterDepot) {
        return toAxios(aftersaleEnterDepotService.save(aftersaleEnterDepot));
    }

    /**
     * 修改
     * @param aftersaleEnterDepot
     * @return
     */
    @PutMapping("update")
    public AxiosResult<Void> update(@RequestBody AftersaleEnterDepot aftersaleEnterDepot) {
        return toAxios(aftersaleEnterDepotService.update(aftersaleEnterDepot));
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @DeleteMapping("batch/{ids}")

    public AxiosResult<Void> batchDeleteByIds(@PathVariable List<Long> ids) {
        return toAxios(aftersaleEnterDepotService.batchDeleteByIds(ids));
    }
}
